/* 
 * Interactive 3D - 2012
 * File Name: main.h
 * Author: s3298400 - To Bao Thien Quan
 */

#ifndef MAIN_H_
#define MAIN_H_

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "obj.h"

#ifdef WIN32
#  include <windows.h>
#endif

#ifdef __APPLE__
#  include <OpenGL/gl.h>
#  include <OpenGL/glu.h>
#  include <GLUT/glut.h>
#else
#  include <GL/gl.h>
#  include <GL/glu.h>
#  include <GL/glut.h>
#endif

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

#ifndef SQRT_2
#define SQRT_2 1.41421356237309504880
#endif

typedef struct Global_t Global;
typedef struct Vertex_t Vertex;
typedef struct Vertex_t Vector;
typedef struct Color_t Color;

struct Color_t
{
	float R, G, B;
};

struct Vertex_t
{
	float x, y, z;
};

struct Global_t
{
	float ship_rotation_speed;
	float ship_angle;
	float ship_moving_speed;
	Vertex ship_position;
	Vector ship_direction;
	Vertex camera_position;
	//Water and View
	float wave_phi;
	float wave_height;
	float wave_speed;
	float wave_popularity;
	float water_edge;

	int wire_debug;
	int axis_debug;
	int normal_debug;
	float axis_length;

	float view_rotate_x;
	float view_rotate_y;
	float nearest;
	float farthest;
	float angle;
	float step;

	//Control
	int left_click;
	int right_click;
	int x_old;
	int y_old;
	int win_W;
	int win_H;
	int scr_W;
	int scr_H;
};

//Main
int main(int argc, char **argv);

//Callbacks
void displayFunc();
void idleFunc();
void reshapeFunc(int width, int height);
void mouseFunc(int button, int state, int x, int y);
void KeyboardFunc(unsigned char key, int x, int y);
void SpecialFunc(int key, int x, int y);
void motionFunc(int x, int y);
//Drawing
void drawAxes(float l);
void drawWater(float l);
void drawMesh(OBJMesh* mesh);
void drawShip();
//Initializers
void create_window();
void openGL_settings();
void set_callbacks();
void initialize_glut_and_global_variables(int argc, char **argv);
Vertex crossProduct3v(Vertex v1, Vertex v2, Vertex v3);
Vertex crossProduct2v(Vertex v1, Vertex v2);
Vertex create_Vertex(float x, float y, float z);
float calculate_Y(float x, float z);
Vertex create_Vector(Vertex v1, Vertex v2);
void set_color(Color color);
Color create_Color(float r, float g, float b);
#endif /* MAIN_H_ */
